package com.secxiot.provider.user.controller;

import com.secxiot.provider.IntegralApi;
import com.secxiot.provider.user.entity.SysExchangeRecord;
import com.secxiot.provider.user.entity.SysExchangeRules;
import com.secxiot.provider.user.service.IntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/integral")
@RestController
public class IntegralController implements IntegralApi {

    @Autowired
    private IntegralService integralService;

    /**
     * 获取兑换规则
     *
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/getExchangeRules")
    public List<SysExchangeRules> getExchangeRules(Long userId) {
        return integralService.getExchangeRules(userId);
    }

    /**
     * 积分兑换
     *
     * @param userId          用户ID
     * @param integralNum     积分数量
     * @param exchangeRulesId 规则ID
     * @return
     */
    @Override
    @PostMapping("/exchange")
    public Integer integralExchange(Long userId, Long integralNum, Long exchangeRulesId) {
        return integralService.integralExchange(userId, integralNum, exchangeRulesId);
    }

    /**
     * 获取兑换列表
     *
     * @param userId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    @GetMapping("/getExchangeRecordList")
    public List<SysExchangeRecord> getExchangeRecordList(Long userId, Long pageNo, Long pageSize) {
        return integralService.getExchangeRecordList(userId, pageNo, pageSize);
    }
}
